package logic

import (
	"context"
	"errors"
	"fmt"
	"go-zero-demo/book/service/user/model"

	"go-zero-demo/book/service/user/cmd/api/internal/svc"
	"go-zero-demo/book/service/user/cmd/api/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type AddUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) AddUserLogic {
	return AddUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddUserLogic) AddUser(req types.UserArray) error {
	// todo: add your logic here and delete this line
	var userArray model.User
	userArray.Name = req.Name
	userArray.Gender = req.Gender
	userArray.Password = req.Password

	userInfo, err := l.svcCtx.UserModel.Insert(userArray)
	if err != nil {
		return errors.New("新增用户错误")
	}
	fmt.Println(userInfo)
	return nil
}
